<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" class="tl-dialog" width="1200px" @open="open" @close="close" top="10px" :append-to-body="true" :modal-append-to-body="true">
    <div style="padding-bottom:10px">
      <!-- 查询界面 -->
      <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
        <template slot="search">
          <el-form-item label="项目名称">
            <el-input v-model="queryParam.qry_name"></el-input>
          </el-form-item>
          <el-form-item label="项目编号">
            <el-input v-model="queryParam.qry_code" style="width:130px"></el-input>
          </el-form-item>
        </template>
      </tl-list-search>
      <!-- 列表界面 -->
      <div>
        <!-- 列表选择 -->
        <div class="table-alert-div" ref="selector">
          <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
            <template slot="title">
              已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRows.length }}</a>项&nbsp;&nbsp;
              <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
            </template>
          </el-alert>
        </div>
        <!--表格渲染-->
        <el-table class="tl-table" ref="mainTable" :height="tableHeight" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
          <el-table-column type="selection" width="55px" fixed="left" v-if="isSingleSelect === false"> </el-table-column>
          <el-table-column prop="dispcustomercode" label="客户名称" width="150px" sortable="custom" sort-by="customercode" align="left" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="name" label="项目名称" width="200px" sortable="custom" sort-by="name" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="areamanagername" label="销售经理" width="100px" sortable="custom" sort-by="areamanagername" align="center" :show-overflow-tooltip="true"></el-table-column>
          <!-- <el-table-column prop="areamanagercode" label="销售经理工号" width="150px" sortable="custom" sort-by="areamanagercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
          <el-table-column prop="projectmanagername" label="项目经理" width="100px" sortable="custom" sort-by="projectmanagername" align="center" :show-overflow-tooltip="true"></el-table-column>
          <!-- <el-table-column prop="projectmanagercode" label="项目经理工号" width="150px" sortable="custom" sort-by="projectmanagercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
          <el-table-column prop="dispcategory" label="项目类别" width="100px" sortable="custom" sort-by="category" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dispprojectstate" label="项目进度状态" width="120px" sortable="custom" sort-by="projectstate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="code" label="项目编号" width="120px" sortable="custom" sort-by="code" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="mandays" label="人天估算" width="80px" sortable="custom" sort-by="mandays" align="right" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="projectmoney" label="项目金额" width="150px" sortable="custom" sort-by="projectmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="contractmoney" label="合同总金额" width="120px" sortable="custom" sort-by="contractmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="billmoney" label="开票总金额" width="120px" sortable="custom" sort-by="billmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="recbillmoney" label="收款总金额" width="120px" sortable="custom" sort-by="recbillmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="receiptmoney" label="收据总金额" width="120px" sortable="custom" sort-by="receiptmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="budgetmoney" label="预算总金额" width="120px" sortable="custom" sort-by="budgetmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="costmoney" label="成本总金额" width="120px" sortable="custom" sort-by="costmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="confirmrevenuemoney" label="确认收入总金额" width="140px" sortable="custom" sort-by="confirmrevenuemoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="purchasemoney" label="采购申请金额" width="120px" sortable="custom" sort-by="purchasemoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="purchasecontractmoney" label="采购合同金额" width="120px" sortable="custom" sort-by="purchasecontractmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="purchasepaymentmoney" label="采购付款金额" width="120px" sortable="custom" sort-by="purchasepaymentmoney" align="right" :formatter="moneyFormat" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="ownerorgname" label="所属公司名称" width="200px" sortable="custom" sort-by="ownerorgname" align="left" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="projectresult" label="项目成果" width="150px" sortable="custom" sort-by="projectresult" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>

          <el-table-column prop="ownerdeptname" label="所属部门名称" width="200px" sortable="custom" sort-by="ownerdeptname" align="left" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="approvalname" label="立项批准人" width="100px" sortable="custom" sort-by="approvalname" align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="approvalcode" label="立项批准人工号" width="150px" sortable="custom" sort-by="approvalcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="reason" label="承接原因" width="200px" sortable="custom" sort-by="reason" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="riskassessment" label="风险评估" width="200px" sortable="custom" sort-by="riskassessment" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="riskcountermeasures" label="应对策略" width="200px" sortable="custom" sort-by="riskcountermeasures" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="approvaltime" label="立项时间" width="170px" sortable="custom" sort-by="approvaltime" align="center" header-align="center" :formatter="dateTimeFormat" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="planstarttime" label="计划开工日期" width="120px" sortable="custom" sort-by="planstarttime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="planendtime" label="计划完工日期" width="120px" sortable="custom" sort-by="planendtime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="actualstarttime" label="实际开工日期" width="120px" sortable="custom" sort-by="actualstarttime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="actualendtime" label="实际完工日期" width="120px" sortable="custom" sort-by="actualendtime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="actualclosetime" label="实际闭环日期" width="120px" sortable="custom" sort-by="actualclosetime" align="center" header-align="center" :formatter="dateFormat" :show-overflow-tooltip="true"></el-table-column>
          <!-- <el-table-column prop="customercode" label="客户编号" width="120px" sortable="custom" sort-by="customercode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
          <el-table-column prop="background" label="项目背景" width="200px" sortable="custom" sort-by="background" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="projecttarget" label="项目目标" width="200px" sortable="custom" sort-by="projecttarget" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <!-- <el-table-column prop="dispprojectlevel" label="项目级别" width="100px" sortable="custom" sort-by="projectlevel" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
          <el-table-column prop="dispoverduestatus" label="超期状态" width="100px" sortable="custom" sort-by="overduestatus" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <!-- <el-table-column prop="ownerdeptcode" label="所属部门编码" width="150px" sortable="custom" sort-by="ownerdeptcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
          <el-table-column prop="overview" label="项目概况" width="200px" sortable="custom" sort-by="overview" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dispprovince" label="所属省份" width="100px" sortable="custom" sort-by="province" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <!-- <el-table-column prop="ownerorgcode" label="所属公司编码" width="150px" sortable="custom" sort-by="ownerorgcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
          <el-table-column prop="dispisincludeproducts" label="是否需要我司提供产品" width="180px" sortable="custom" sort-by="isincludeproducts" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="productdetails" label="产品明细" width="200px" sortable="custom" sort-by="productdetails" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="dispispurchase" label="是否外包" width="100px" sortable="custom" sort-by="ispurchase" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column prop="purchasedescription" label="外包说明" width="200px" sortable="custom" sort-by="purchasedescription" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
          <el-table-column label="操作" width="80px" align="center" fixed="right" v-if="isSingleSelect === true">
            <template slot-scope="scope">
              <el-button type="text" icon="el-icon-finished" @click="doSelectData(scope.row[fieldDefaultKey])">选择</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 列表分页 -->
        <el-row class="pagebar" ref="pager">
          <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
        </el-row>
      </div>
    </div>
    <div slot="footer" class="dialog-footer" v-if="isSingleSelect === false">
      <el-button type="text" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doConfirm">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_ref_list } from '@tapui/mixins/mixin_ref_list'
/** 子组件 */
/** 工具类 */
import { queryDataCode } from '@tapui/api/dataCode'
import { getAction, putAction, postAction } from '@tapui/utils/http'
import { rmbFormat } from '../../../utils/calculation'
/** VUE配置 */
export default {
  name: 'TlPmProjectRef',
  components: {},
  mixins: [mixin_ref_list],
  data() {
    return {
      description: '项目基本信息参照页面',
      // 默认Key字段名
      fieldDefaultKey: 'id',
      // 默认显示字段名
      fieldDefaultValue: 'name',
      // url配置
      url: {
        list: '/pm/project/refList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'sortcode',
        sord: 'asc'
      }
    }
  },
  props: {
    title: {
      default: '项目选择',
      type: String
    },
    isHeaderDisplay: {
      default: true,
      type: Boolean
    },
    isDisplayDefaultElement: {
      default: true,
      type: Boolean
    },
    width: {
      default: '',
      type: String
    },
    initDisplayData: {
      default: '',
      type: String
    }
  },
  methods: {
    moneyFormat(row, column, cellValue, index) {
      return rmbFormat(row[column.property])
    }
  }
}
</script>
